<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Lines</title>
	<link rel="stylesheet" href="../css/style.css">
	<script type="text/javascript" src="../../lib/paper.js"></script>
	<script type="text/paperscript" canvas="canvas">
		var amount = 180;
		for (var i = 0; i < amount; i++) {
			var path = new Path();
			path.fillColor = new HsbColor(1, 1, Math.random());
			path.strokeCap = 'round';
			path.closed = true;
		}

		var position = view.center;
		var mousePos = position;
		var children = project.activeLayer.children;
		var count = 0;

		function iterate() {
			count++;
			var delta = (mousePos - position);
			position += delta / 10;
			for (var i = 1; i < amount; i++) {
				var path = children[i];
				var length = Math.abs(Math.sin(i + count / 20) * 300);
				path.segments = [
					position + delta / 1.5,
					position + { angle: i * 2, length: length },
					position + { angle: (i + 1) * 2, length: length }
				];
				path.fillColor.hue = count - length;
			}
		}

		function onFrame() {
			iterate();
		}

		function onMouseMove(event) {
			iterate();
			mousePos = event.point;
		}
	</script>
</head>
<body style='background-color:black'>
	<canvas id="canvas" resize></canvas>
</body>
</html>